// The template compiler attempts to minimize the need for normalization by
// statically analyzing the template at compile time.
//
// For plain HTML markup, normalization can be completely skipped because the
// generated render function is guaranteed to return Array<VNode>. There are
// two cases where extra normalization is needed:

// 1. When the children contains components - because a functional component
// may return an Array instead of a single root. In this case, just a simple
// normalization is needed - if any child is an Array, we flatten the whole
// thing with Array.prototype.concat. It is guaranteed to be only 1-level deep
// because functional components already normalize their own children.
// 模板编译器尝试最小化标准化的需要
// 在编译时静态分析模板。
// 对于纯HTML标记，可以完全跳过规范化，因为
// 生成的渲染函数保证返回arrayvnode & gt; 有
// 两种情况下需要额外的规范化:
// 1. 当子组件包含时——因为是功能组件
// 可以返回一个数组而不是单个根。在这种情况下，只是一个简单的
// 需要标准化——如果任何一个子数组是数组，我们就将整个数组平化
// Array.prototype.concat。它保证只有1级深
// 因为功能组件已经正常化了它们自己的孩子。
export function simpleNormalizeChildren(children: any) {
  for (let i = 0; i < children.length; i++) {
    if (Array.isArray(children[i])) {
      return Array.prototype.concat.apply([], children)
    }
  }
  return children
}

// 2. When the children contains constructs that always generated nested Arrays,
// e.g. <template>, <slot>, v-for, or when the children is provided by user
// with hand-written render functions / JSX. In such cases a full normalization
// is needed to cater to all possible types of children values.
// 2。当子元素包含总是生成嵌套数组的构造时，
//例如:template&gt; &lt;slot&gt;， v-for，或当儿童是由用户提供
//用手写的呈现函数/ JSX。在这种情况下，是完全规范化
//是需要的，以满足所有可能的儿童值类型。
export function normalizeChildren(children: any): ?Array<VNode> {
  return isPrimitive(children)
    ? [createTextVNode(children)]
    : Array.isArray(children)
      ? normalizeArrayChildren(children)
      : undefined
}